import fs from 'node:fs'
import YAML from 'yaml'
import { __dirname } from '../../main.js'
const __diryaml = `${__dirname}/config/parameter/cooling.yaml`
export const getConfig = ({ app, name }) => {
    //获得配置地址
    const file = `${__dirname}/config/${app}/${name}.yaml`
    //读取配置
    const data = YAML.parse(fs.readFileSync(file, 'utf8'))
    return data
}
export const updataConfig = ({ name, size }) => {
    const map = {
        '配置名': 'CD.up',
    }
    if (map.hasOwnProperty(name)) {
        const [name0, name1] = map[name].split('.')
        const data = YAML.parse(fs.readFileSync(`${__diryaml}`, 'utf8'))
        data[name0][name1] = Number(size)
        const yamlStr = YAML.stringify(data)
        fs.writeFileSync(`${__diryaml}`, yamlStr, 'utf8')
        return `修改${name}为${size}`
    } else {
        return '无次项配置信息'
    }
}